/**
 * API 统一入口文件
 * 提供便捷的API调用方式
 */

// 导出基础工具
export { default as request } from '@/utils/request'
export { BaseApiService, ApiService } from './base'
export { API_CONFIG, getApiUrl, HTTP_STATUS, BUSINESS_CODE } from '@/config'

// 导出认证相关API
export * from './auth'

// 导出摄像头相关API
export * from './camera'

// 导出用户相关API
export * from './user'

// 导出菜单相关API
export * from './menu'

// 导出角色相关API
export * from './role'

// 导出组织架构相关API
export * from './organize'

/**
 * 创建快捷的API调用实例
 */
import { BaseApiService, ApiService } from './base'
import { AuthService } from './auth'
import { CameraService } from './camera'
import { RoleService } from './role'
import { OrganizeService } from './organize'

export const api = {
  // 认证服务
  auth: new AuthService(),
  
  // 摄像头服务
  camera: new CameraService(),
  
  // 用户服务
  user: new BaseApiService('/users'),
  
  // 菜单服务
  menu: new BaseApiService('/menus'),
  
  // 角色服务
  role: new RoleService(),

  // 组织架构服务
  organize: new OrganizeService(),
  
  // 设备管理服务
  device: {
    stream: new BaseApiService('/devices/streams'),
    nmc: new BaseApiService('/devices/nmc')
  },
  
  // 报警服务
  alarm: new BaseApiService('/alarms')
}

/**
 * 常用的API组合调用
 */
export const apiCommon = {
  /**
   * 获取首页必要数据
   */
  async getDashboardData() {
    return ApiService.parallel({
      userInfo: () => api.auth.getUserInfo(),
      cameraList: () => api.camera.getList({ page: 1, pageSize: 10 }),
      alarmList: () => api.alarm.getList({ page: 1, pageSize: 5 })
    })
  },

  /**
   * 获取系统管理页面数据
   */
  async getSystemData() {
    return ApiService.parallel({
      userList: () => api.user.getList({ page: 1, pageSize: 20 }),
      menuList: () => api.menu.getList({ page: 1, pageSize: 100 }),
      roleList: () => api.role.getAllRoles()
    })
  },

  /**
   * 获取设备管理页面数据
   */
  async getDeviceData() {
    return ApiService.parallel({
      streamList: () => api.device.stream.getList({ page: 1, pageSize: 20 }),
      nmcList: () => api.device.nmc.getList({ page: 1, pageSize: 20 })
    })
  }
}

export default api